import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class ActivitySubSystem {

    private List<Activity> activityList = new ArrayList<>();

    public void addActivity(Activity activity){
        this.activityList.add(activity);
    }

    public void removeActivityById(String id){
        Iterator<Activity> acitivityIterator = activityList.iterator();
        while(acitivityIterator.hasNext()){
            Activity activity = acitivityIterator.next();
            if(activity.getId().equals(id)){
                acitivityIterator.remove();
            }
        }
    }

    public Activity getActivityById(String id){
        for (Activity activity :activityList) {
            if(activity.getId().equals(id)){
                return activity;
            }
        }
        return null;
    }

    public List<Activity> getActivitiesByDate(Date date){

        List<Activity> ret = new ArrayList<>();
        for (Activity activity :activityList) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date1 = activity.getStartTime();
            Date date2 = activity.getEndTime();

            int compareTo = date1.compareTo(date);
            int compareTo2 = date2.compareTo(date);

            if(compareTo <= 0 && compareTo2 >= 0){
                ret.add(activity);
            }
        }
        return ret;
    }

    //题意表述不清，随便写的
    public List<Activity> getAcitivityList() {
        return activityList;
    }

    public int checkActivityNumOfTeam(String teamId){
        for (Activity acitivity:activityList) {
            List<Team> teams = acitivity.teams;
            for (Team team:teams) {
                if(team.getTeamId().equals(teamId)){
                    return 1;
                }
            }
        }
        return 0;

    }


}
